//
//  YSCustomShareBtn.m
//  Yueshi
//
//  Created by Northwan on 15/9/25.
//  Copyright © 2015年 悦食中国. All rights reserved.
//

#import "YSCustomShareBtn.h"

// 按钮高度的比例
#define kImageBiLi 0.8
#define kImageWidth SCREENW/8
#define kTitleFont 15

@implementation YSCustomShareBtn

#pragma mark 任何方式(代码)创建按钮都会调用这个方法
- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        // 设置按钮文字颜色
        [self setTitleColor:publicTextColor forState:UIControlStateNormal];
        // 设置按钮文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        // 让图片按照原来的宽高比显示出来
        self.imageView.contentMode = UIViewContentModeScaleToFill;
        // 设置按钮文字的字体
        self.titleLabel.font = [UIFont systemFontOfSize:kTitleFont];
        // 设置按钮里面的内容（UILabel、UIImageView）居中
        // btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        
    }
    return self;
}

#pragma mark - 重写了UIButton的方法
#pragma mark 控制UILabel的位置和尺寸
// contentRect其实就是按钮的位置和尺寸
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleX = 0;
    CGFloat titleY = contentRect.size.height * kImageBiLi;
    CGFloat titleWidth = contentRect.size.width;
    CGFloat titleHeight = kTitleFont;
    
    return CGRectMake(titleX, titleY, titleWidth, titleHeight);
}

#pragma mark 控制UIImageView的位置和尺寸
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageX = (contentRect.size.width - kImageWidth)*0.5;
    CGFloat imageY = (contentRect.size.height * kImageBiLi-kImageWidth)*0.7;
    CGFloat imageWidth = kImageWidth;
    CGFloat imageHeight = kImageWidth;
    return CGRectMake(imageX, imageY, imageWidth, imageHeight);
}


@end
